﻿#region Using Directives

using System;
using System.Text;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Collections.Generic;

using QuickDev.Localization;

using QuickDev.Model;
using QuickDev.Caching;

#endregion

namespace QuickDev.Services
{
    public class ServiceUtility
    {
        #region Methods

        #region Common

        /// <summary>
        /// Gets the formatted amount.
        /// </summary>
        /// <param name="amount">The amount.</param>
        /// <param name="formatWithCurrencySymbol">if set to <c>true</c> [format with currency symbol].</param>
        /// <returns></returns>
        public static string GetFormattedAmount( decimal amount, bool formatWithCurrencySymbol )
        {
            SiteSettings siteSettings = SiteSettingsCache.GetCachedModel();
            CultureInfo cultureInfo = new CultureInfo( siteSettings.Language );
            if ( formatWithCurrencySymbol )
            {
                return string.Format( "{0} {1}", siteSettings.CurrencySymbol, decimal.Round( amount, cultureInfo.NumberFormat.CurrencyDecimalDigits ).ToString( cultureInfo ) );
            }
            else
            {
                return decimal.Round( amount, cultureInfo.NumberFormat.CurrencyDecimalDigits ).ToString( cultureInfo );
            }
        }

        /// <summary>
        /// Gets the formatted amount.
        /// </summary>
        /// <param name="amount">The amount.</param>
        /// <param name="formatWithCurrencySymbol">if set to <c>true</c> [format with currency symbol].</param>
        /// <returns></returns>
        public static string GetFormattedAmount( string amount, bool formatWithCurrencySymbol )
        {
            decimal parsedAmount = 0;
            parsedAmount = decimal.Parse( amount );
            return GetFormattedAmount( parsedAmount, formatWithCurrencySymbol );
        }

        /// <summary>
        /// Gets the formatted date.
        /// </summary>
        /// <param name="date">The date.</param>
        /// <returns></returns>
        public static string GetFormattedDate( DateTime date )
        {
            SiteSettings siteSettings = SiteSettingsCache.GetCachedModel();
            CultureInfo cultureInfo = new CultureInfo( siteSettings.Language );
            return date.ToString( "ddd , MMMM  d , yyyy", cultureInfo );
        }

        #endregion

        #region ReturnDB

        /// <summary>
        /// protected string GetFormattedStatus( int statusId , string statusName )
        /// </summary>
        /// <param name="statusId">statusId</param>
        /// <param name="statusName">statusName</param>
        /// <returns>Formatted Status String</returns>
        public static string GetFormattedStatus( int statusId , string statusName )
        {
            return String.Format( "<span class=\"Status_{0}\">{1}</span>" , statusId , statusName );
        }

        #endregion

        #endregion
    }
}